﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.ProtocolProfile
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Security;

namespace Microsoft.InfoCards
{
  internal class ProtocolProfile
  {
    private static WSSecurityTokenSerializer s_tokenSerializerDefault = new WSSecurityTokenSerializer(MessageSecurityVersion.Default.SecurityVersion, true);
    private static WSSecurityTokenSerializer s_tokenSerializerWSTrust13 = new WSSecurityTokenSerializer(SecurityVersion.WSSecurity11, TrustVersion.WSTrust13, SecureConversationVersion.WSSecureConversation13, false, (SamlSerializer) null, (SecurityStateEncoder) null, (IEnumerable<Type>) null);
    private XmlNames.IWSTrust m_iWSTrust = (XmlNames.IWSTrust) XmlNames.WSTrustXmlSoap2005.Instance;
    private XmlNames.IWSPolicy m_iWSPolicy = (XmlNames.IWSPolicy) XmlNames.WSPolicyXmlSoap2004.Instance;

    public XmlNames.IWSTrust WSTrust
    {
      get
      {
        return this.m_iWSTrust;
      }
      set
      {
        this.m_iWSTrust = value;
      }
    }

    public XmlNames.IWSPolicy WSPolicy
    {
      get
      {
        return this.m_iWSPolicy;
      }
    }

    public MessageSecurityVersion MsgSecurityVersion
    {
      get
      {
        if (XmlNames.WSSpecificationVersion.WSTrustXmlSoap2005 == this.WSTrust.Version)
          return MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11;
        if (XmlNames.WSSpecificationVersion.WSTrustOasis2007 == this.WSTrust.Version)
          return MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12;
        return MessageSecurityVersion.Default;
      }
    }

    public WSSecurityTokenSerializer TokenSerializer
    {
      get
      {
        if (XmlNames.WSSpecificationVersion.WSTrustOasis2007 == this.WSTrust.Version)
          return ProtocolProfile.s_tokenSerializerWSTrust13;
        return ProtocolProfile.s_tokenSerializerDefault;
      }
    }

    public ProtocolProfile()
    {
    }

    public ProtocolProfile(string policyXml)
    {
      if (policyXml.Contains(XmlNames.WSTrustXmlSoap2005.Instance.Namespace))
        this.m_iWSTrust = (XmlNames.IWSTrust) XmlNames.WSTrustXmlSoap2005.Instance;
      else if (policyXml.Contains(XmlNames.WSTrustOasis2007.Instance.Namespace))
        this.m_iWSTrust = (XmlNames.IWSTrust) XmlNames.WSTrustOasis2007.Instance;
      if (policyXml.Contains(XmlNames.WSPolicyXmlSoap2004.Instance.Namespace))
      {
        this.m_iWSPolicy = (XmlNames.IWSPolicy) XmlNames.WSPolicyXmlSoap2004.Instance;
      }
      else
      {
        if (!policyXml.Contains(XmlNames.WSPolicyW32007.Instance.Namespace))
          return;
        this.m_iWSPolicy = (XmlNames.IWSPolicy) XmlNames.WSPolicyW32007.Instance;
      }
    }
  }
}
